package com.starsea.book.ui.newpage.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.util.ScreenUtils
import com.blankj.utilcode.util.SizeUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.starsea.book.databinding.ItemBookCityTopBinding
import com.starsea.book.ui.newpage.entity.BookInfoEntity
import com.starsea.book.ui.newpage.utils.loadNormalImage

/**
 * @author Lee
 * @createTime 2024-07-12 20 GMT+8
 * @desc :
 */
class BookCityTopAdapter(var mContext: Context) :
    BaseQuickAdapter<BookInfoEntity, BookCityTopAdapter.MyViewHolder>() {

    override fun onBindViewHolder(holder: MyViewHolder, position: Int, item: BookInfoEntity?) {
        holder.binding.ivCover.loadNormalImage(mContext, item!!.bookCover ?: "")

        val layoutParams = holder.binding.cvImg.layoutParams as ConstraintLayout.LayoutParams
        layoutParams.width =
            ((ScreenUtils.getScreenWidth() - SizeUtils.dp2px(24f + 14f + 4 * 12f)) / 4.0).toInt()
//
        layoutParams.height =
            ((layoutParams.width) * 96.0 / 72.0).toInt()

        holder.binding.cvImg.layoutParams = layoutParams

        holder.binding.tvTitle.text = item.bookTitle
        holder.binding.tvDesc.text = item.bookDesc
//    holder.binding.rtvVipTag.visibleOrGone(item.isVipBook == 1)
    }

    override fun onCreateViewHolder(
        context: Context,
        parent: ViewGroup,
        viewType: Int,
    ): MyViewHolder {
        return MyViewHolder(parent = parent)
    }

    class MyViewHolder(
        parent: ViewGroup,
        val binding: ItemBookCityTopBinding = ItemBookCityTopBinding.inflate(
            LayoutInflater.from(parent.context), parent, false
        ),
    ) : RecyclerView.ViewHolder(binding.root)

}